﻿using System;
using Newtonsoft.Json;
using UnityEngine;

namespace province
{
    public class CountryData
    {
        [JsonProperty("name")]
        public String name { get; set; } //国家名称
        [JsonProperty("r")]
        public float r { get; set; }
        [JsonProperty("g")]
        public float g { get; set; }
        [JsonProperty("b")]
        public float b { get; set; }
        [JsonProperty("tag")]
        public String tag { get; set; } //国家代码
        [JsonIgnore]
        public Color color { get; set; }
        
        public CountryData()
        {
            tag = " ";
        }

        public void InitFromJson()
        {
            this.color = new Color(r/255f, g/255f, b/255f);
            tag = tag.ToUpper();
        }
        public void InitFromBytes()
        {
            this.color = new Color(r/255f, g/255f, b/255f);
            tag = tag.ToUpper();
        }


        public CountryData(string name, Color32 loadColor, string tag)
        {
            this.name = name;
            this.tag = tag;
        }

        public CountryData(string name, Color32 loadColor)
        {
            this.name = name;
            tag = " ";
        }

        public override string ToString()
        {
            return $"{nameof(name)}: {name},  {nameof(tag)}: {tag}";
        }
    }
}